#ifndef CRENDERQUEUESORTER_H_INCLUDED
#define CRENDERQUEUESORTER_H_INCLUDED

#include "IRenderQueue.h"
#include <vector>

//using namespace std;

class IInstance;
class IVertexBuffer;
class IEffect;

typedef std::vector<IInstance*> instances;

/// Render list for a state
/** This render list is used only in the following realization of a render queue. It is intended to store an array of instances to
	 the same renderable. These instances can be sorted by depth from the camera, and even hardwarely instanced. */
class CRenderList {
	protected:
		// Private data:
		IRenderable*	m_pRenderable;				///< Instance of the renderable
		instances		m_vecRawRenderList;		///< List of instances in order of insertion

	public:
		void	Process	( IRenderTarget* rt );
		void  ProcessGeometryOnly( IRenderTarget* rt );
		void	Insert	( IInstance* object );
		void	Clear		( );
		void	Sort		( );

		bool operator < ( const CRenderList& data ) const {
			return m_pRenderable < data.m_pRenderable;
		}

		 // Constructor & Destructor
		 CRenderList( IRenderable* renderable = 0 );
		~CRenderList( );
};

typedef std::vector<CRenderList> renderlists;

/// Sorting queue realization
/**	This realization of a render queue is intended to stack renderables and instances, sort them and at the end render them at once. */
class CRenderQueueSorter : public IRenderQueue {
protected:
	renderlists m_vecRawScene; ///< The scene queue, unsorted

private:

public:
		// Public functions:
		void	Process			( IRenderTarget* rt );
		void	ProcessAndKeep	( IRenderTarget* rt );
		void	Enqueue			( IInstance* 	instance, IRenderable* renderable );
		void	Enqueue			( IInstance* 	instance 	);
		void	Enqueue			( IRenderable* renderable 	);
		void	Clear				( );
		void	Sort				( );

				// Constructor & Destructor
			   CRenderQueueSorter( );
	virtual ~CRenderQueueSorter( );
};


#endif // CRENDERQUEUESORTER_H_INCLUDED
